package ee.siimkaspar.subjects.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import ee.siimkaspar.subjects.model.UserAccount;
import ee.siimkaspar.subjects.service.UserService;

@Controller
@RequestMapping("/user")
public class UserDataApi {

	@Autowired
	private UserService uService;
	
	@RequestMapping(value="/{id}", method = RequestMethod.GET)
	public @ResponseBody String getUserData(@PathVariable Integer id) {
		UserAccount user = uService.findObject(UserAccount.class, id);
		if (user == null) {
			return null;
		}
		return "{\"id\":\"" + user.getId() + "\", \"username\":\"" + user.getUsername() + "\"}";
	}
}
